package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// WebshellLog webshell 日志
type WebshellLog struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:bigint;size:64;comment:主键"`
	RobotID   string `json:"robot_id" gorm:"column:robot_id;type:string;size:40;comment:机器id"`
	Content   string `json:"content" gorm:"column:content;type:string;size:512;comment:命令内容"`
	UserID    string `json:"user_id" gorm:"column:user_id;type:string;size:20;comment:用户id"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:false;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (WebshellLog) TableName() string {
	return "webshell_log"
}

// BeforeCreate 自增id
func (u *WebshellLog) BeforeCreate(tx *gorm.DB) (err error) {
	if u.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	u.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &WebshellLog{})
}
